package com.elastic.inis;

import com.elastic.ESMajorManage;
import com.elastic.chain.FinalLeader;
import com.elastic.chain.Leader;
import com.elastic.chain.QueryAdapter;
import org.elasticsearch.index.query.BoolQueryBuilder;

/**
 * @ClassName DefaultBuilder
 * @Author xiezhuocai
 * @Description 初始化
 * @Date 2021/12/30 10:37
 */
public class DefaultBuilder extends  BuilderManage {

    public DefaultBuilder(ESMajorManage majorManage){
        this.esProduct = new ESProduct(majorManage);
    }

    @Override
    public void buildFinalLeader() {
        if (this.esProduct.getMajorManage().getFinalLeader() == null) {
            this.esProduct.initFinalLeader(new FinalLeader());
        }
    }

    @Override
    public void buildLeader() {
        Leader leader = new Leader() {
            @Override
            public boolean handleRequest(BoolQueryBuilder boolQuery, String key, Object value) {
                return false;
            }
        };
        this.esProduct.initLeader(leader);
        if (this.esProduct.getMajorManage().getFinalLeader() == null) {
            buildFinalLeader();
        }
        leader.setNext(this.esProduct.getMajorManage().getFinalLeader());
    }

    @Override
    public void buildChooseQuery() {
        this.esProduct.initChooseQuery(new QueryAdapter());
    }


}
